
const state = () => ({
  headMenu: JSON.parse(window.localStorage.getItem("menu")),
  asideMenu:{},
  isCollapse:false
})
const getters = {
  head: (state) => state.headMenu,
  isCollapse:( state ) => state.isCollapse,
  aside: (state) => {
    if(state.asideMenu.path){
      return state.asideMenu
    }
    let menu = {};
    let path = location.pathname.split('/');
    state.headMenu.forEach((item,index) => {
      if(item.path == '/'+path[2]){
        menu = item
        state.asideMenu = item
      }
    })
    return menu
  }
}
const mutations = {
  setHeadMenu(state, data) {
    state.headMenu = data
  },
  setAsideMenu(state, data) {
    state.asideMenu = data
  },
  setCollapse(state,data){
    state.isCollapse = data
  }
}
const actions = {
  setCollapse({commit}, data) {
    commit('setCollapse',data)
  },
  setHead({ commit }, data) {
    commit('setHeadMenu', data)
    window.localStorage.setItem('menu',JSON.stringify(data))
  },
  setAside({ commit }, data) {
    commit('setAsideMenu', data)
  }
}
export default { state, getters, mutations, actions }